package graphics.raytracing;

import java.util.ArrayList;
import java.util.Collection;

public class RayRunner
{
	int i =0;
	Collection<Runnable> runables=new ArrayList<>();
	void registerRay(Runnable r)
	{
		if(i>500000)
		{
			final Collection<Runnable> t=runables;
			t.add(r);
			runables = new ArrayList<>();
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					for(Runnable r:t)
						r.run();
				}
			}).start();
			i=0;
			return;
		}
		runables.add(r);
		i++;
	}
	public void boom() {
		System.out.println("left:"+ runables.size());
		for(Runnable r:runables)
			r.run();
	}
}